/*
 * JsonResultMap.java
 * 
 */
package cn.knet.sp.ncrm.common.vo;

import java.util.HashMap;
import java.util.Map;

import cn.knet.sp.ncrm.common.mapper.JsonMapper;

/**
 * 类说明.
 *
 * @version 1.0
 */
public class JsonResultMap {
	private Map<String, Object> resultMap = new HashMap<String, Object>();
	private static final String STATUS_FLAG = "status";
	private static final String MESSAGE = "message";
	private static final String STATUS_CODE = "statusCode";
	private static final String RESULT_CODE = "resultCode";
	private static final String RESULT_MSG = "resultMsg";
	private static final String RESULT = "result";
	
	private JsonResultMap(boolean status) {
		resultMap.put(STATUS_FLAG, status);
	}
	
	public static JsonResultMap getJsonResultMap(boolean status) {
		return new JsonResultMap(status);
	}
	
	public JsonResultMap addErrorMessage(String errorMessage) {
		setStatus(false);
		resultMap.put(MESSAGE, errorMessage);
		return this;
	}
	public JsonResultMap addMessage(String message) {
		resultMap.put(MESSAGE, message);
		return this;
	}
	public JsonResultMap addResultCode(String resultCode) {
		resultMap.put(RESULT_CODE, resultCode);
		return this;
	}
	public JsonResultMap addResultMsg(String resultMsg) {
		resultMap.put(RESULT_MSG, resultMsg);
		return this;
	}
	public JsonResultMap addResult(Object value) {
		resultMap.put(RESULT, value);
		return this;
	}
	
	public JsonResultMap setStatus(boolean status) {
		resultMap.put(STATUS_FLAG, status);
		return this;
	}
	public JsonResultMap addStatusCode(int statusCode) {
		resultMap.put(STATUS_CODE, statusCode);
		return this;
	}
	
	public JsonResultMap put(String key, Object value) {
		resultMap.put(key, value);
		return this;
	}
	
	public Map<String, Object> getMap() {
		return resultMap;
	}
	
	public String toJson() {
		return JsonMapper.toJsonString(resultMap);
	}
}
